/*
 * 作者：姚俊
 * 功能：获奖审核失败的action
 * 日期：2015-05-29
 */
package admin.action.checkFruits;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import admin.email.SendEmail;
import admin.service.fruits.AwardService;
import teacher.bean.Award;
import teacher.bean.Flow;
import teacher.bean.Teacher;
import teacher.service.award;
import teacher.service.flow;
import teacher.service.teacher;

public class AwardCheckFailAction {
	
	private Award award1;

	
	public Award getAward1() {
		return award1;
	}

	public void setAward1(Award award1) {
		this.award1 = award1;
	}


	public String execute()
	{
		
		Award awa=new AwardService().getAward(this.getAward1());
		Teacher tea=new teacher().SelectTeaByAwa(awa);
		if(tea!=null)
		{
			awa.setState(3);
			new AwardService().updateAward(awa, this.getAward1());

				//发送邮件
				try {
					SendEmail.send_email(tea.getMail(), "获奖审核不成功","很遗憾"+tea.getName()+",你的获奖文件审核不通过，已经被驳回！如有疑问，请联系方向管理员。");
				} catch (AddressException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (MessagingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			
		}
//		流程管理开始
		Award a=new Award();
		a=new award().selectAwardById(award1.getAwaId());
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Flow f=new Flow();
		f.setFruitId(a.getAwaId());
		f.setFruitKind(3);
		f.setDirDo(2);
		f.setDirTime(df.format(new Date()));
		f.setSubDo(1);
		f.setSubTime(df.format(new Date()));
		f.setTeaDo(2);
		f.setTeaTime(df.format(new Date()));
//		流程管理结束
		if(new flow().insertFlow(f)){
			return "succ";
		}else{
			return "succ";
		}
	}

}
